﻿package com.eitb.plantillas{
	import flash.text.*;
	import flash.geom.*;
	import flash.events.*;
	import flash.display.*;
	import com.google.maps.*;
	import com.eitb.programas.*;
	import com.eitb.cargadores.*;
	import com.google.maps.controls.*;	
	import com.google.maps.interfaces.*;	
	import com.eitb.programas.menu.*;	
	public class PlantillaMapa extends Sprite implements IVistaPlantilla, IVistaPlantillaMapa {
		public static const MAP_KEY_WWW_EITB_COM:String = "ABQIAAAAy7T50F-LGhLHC3UKVHeASRTvxcouBNqCcDEHCLtbAxQF_-mSdxTGIuQ5I1LfOkw0kKRbpFKfH9JpHQ";
		public static const MAP_KEY_WWW_ORG4_EITB_COM:String = "ABQIAAAAy7T50F-LGhLHC3UKVHeASRQQF_pivtuBuwrayTyTNEZswDUTdBSNYjaxNLcTD9_9TkT4z2OoTZeEnw";
		public static const MAP_KEY_TEST_EITB_COM:String = "ABQIAAAAy7T50F-LGhLHC3UKVHeASRQQF_pivtuBuwrayTyTNEZswDUTdBSNYjaxNLcTD9_9TkT4z2OoTZeEnw";
		
		private var cPrograma:IControladorPrograma;
		private var cPlantilla:IControladorPlantilla;
		private var cPlantillaMapa:IControladorPlantillaMapa;
		
		private var map:Map;
		private var texto:TextField;	
		public function PlantillaMapa():void {	
		}

		public function initControladorPrograma(cPrograma:IControladorPrograma):void {
			this.cPrograma = cPrograma;
		}
		
		public function initControladorPlantilla(cPlantilla:IControladorPlantilla):void {
			this.cPlantilla = cPlantilla;
		}

		public function initControladorPlantillaMapa(cPlantilla:IControladorPlantillaMapa):void {
			this.cPlantillaMapa = cPlantillaMapa;
		}

		
		public function getCPrograma():IControladorPrograma {
			return this.cPrograma;
		}
		
		public function getCPlantilla():IControladorPlantilla {
			return this.cPlantilla;
		}

		public function getDisplayObject():DisplayObject {
			return DisplayObject(this);
		}
		
		public function setVisible(mostrar:Boolean):void {
			this.visible=mostrar;
		}
		
		public function initMap():void {
			map = new Map();
			map.key = MAP_KEY_WWW_EITB_COM;
			map.setSize(new Point(this.width, this.height));
			this.addChild(map);			
		}

		public function initText():void {
			//en este campo vamos a imprimir las coordenadas y zoom actuales, si comentan estas líneas pueden ocultar esta parte 
			texto = new TextField();
			var formatoTexto:TextFormat = new TextFormat();
			this.addChild(texto);
			formatoTexto.font = "Arial";
			formatoTexto.size = 12;
			formatoTexto.align = TextFormatAlign.LEFT;
			formatoTexto.bold = true;
			texto.multiline = true;
			texto.background = true;
			texto.autoSize = TextFieldAutoSize.LEFT;
			texto.defaultTextFormat = formatoTexto;
			//si se cargo todo bien ejecutamos! 			
		}

		public function addMapEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void{
			this.map.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		
		public function addControl(control:IControl):void {
			this.map.addControl(control);
		}
		public function setCenter(latLng:LatLng, opt_zoom:Number, opt_mapType:IMapType = null):void {
			this.map.setCenter(latLng, opt_zoom, opt_mapType);
		}
		public function setZoom(level:Number):void{
			this.map.setZoom(level);
		}
		
		public function setText(texto:String):void{
			this.texto.text = texto;
		}
		public function setLocation(point:Point):void{
			this.texto.x = point.x;
			this.texto.y = point.y;
			this.texto.visible = true;
		}

		public function addOverlay(overlay:IOverlay):void {
			this.map.addOverlay(overlay);
		}
		public function setMapType(mapType:IMapType):void {
			this.map.setMapType(mapType);
		}
	}
}